package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DictionariesItem;
import cn.wolfcode.crm.query.DictionariesQuery;
import cn.wolfcode.crm.service.IDictionariesItemService;
import cn.wolfcode.crm.service.IDictionariesService;
import cn.wolfcode.crm.util.JsonResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dictionariesItem")
public class DictionariesItemController {

    @Autowired
    private IDictionariesItemService dictionariesItemService;

    @Autowired
    private IDictionariesService dictionariesService;

    @RequiresPermissions(value = {"dictionariesItem:view", "数据字典视图"}, logical = Logical.OR)
    @RequestMapping("/view")
    public String dictionaries(){

        return "system/dictionaries";
    }

    //分页查询
    @RequiresPermissions(value = {"dictionariesItem:query", "数据字典列表"}, logical = Logical.OR)
    @RequestMapping("/query")
    @ResponseBody
    public Object query(DictionariesQuery qo){
        return dictionariesItemService.query(qo);
    }

    @RequiresPermissions(value = {"dictionariesItem:combobox", "下拉框显示"}, logical = Logical.OR)
    @RequestMapping("/combobox")
    @ResponseBody
    public List<?>  combobox(){
        return dictionariesService.listAll();
    }


    //保存编辑
    @RequiresPermissions(value = {"dictionariesItem:save", "数据字典明细新增/编辑"}, logical = Logical.OR)
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(DictionariesItem entity){
        try {
            dictionariesItemService.saveOrUpdate(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new JsonResult().mark(ex.getMessage());
        }
        return new JsonResult();
    }

    //删除数据字典
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        dictionariesItemService.delete(id);
        return new JsonResult();
    }



}
